package com.lx.yygh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lx.yygh.common.result.Result;
import com.lx.yygh.model.order.OrderInfo;
import com.lx.yygh.model.user.Patient;
import com.lx.yygh.service.OrderService;
import com.lx.yygh.user.client.PatientFeignClient;
import com.lx.yygh.vo.order.OrderQueryVo;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author c先生
 * @date 2022年10月31日 下午 2:15:48
 * @describe
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/admin/order/orderInfo")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    PatientFeignClient patientFeignClient;

    @ApiOperation(value = "分页获取订单列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable("page")Integer page,
                              @PathVariable("limit")Integer limit,
                              OrderQueryVo orderQueryVo, HttpServletRequest request){
        IPage<OrderInfo> orderInfoIPage = orderService.getPageList(page,limit,orderQueryVo);
    return Result.ok(orderInfoIPage);
    }

    @ApiOperation(value = "获取订单状态列表")
    @GetMapping("/getStatusList")
    public Result getStatusList(){
        List<Map<String, Object>>  statusList = orderService.getStatusList();
        return Result.ok(statusList);
    }

    @ApiOperation(value = "获取订单的详细信息")
    @GetMapping("/show/{id}")
    public Result show(@PathVariable("id")Long id){
        HashMap<String, Object> map = new HashMap<>();
        OrderInfo orderInfo = orderService.getOrderInfoById(id);
        Long patientId = orderInfo.getPatientId();
        Patient patient = patientFeignClient.getPatientById(patientId);
        map.put("orderInfo",orderInfo);
        map.put("patient",patient);
        return Result.ok(map);
    }
}
